(defun simple (list)
  (cond ((equal 'a (first list))
	 (print "A!")) 
	((equal 'b (first list))
	 (print "B!"))
	(t (error "Can't happen!"))))

(defun check-args (list)
  (dolist (arg list t)
	  (when (not (numberp arg)) (return nil))))

(defun simple2 (list)
  (let ((sum1 0)(sum2 0))
    (when (not (check-args list))
	  (error "simple2: Non-numeric args!"))
    (dolist (element list)
	    (setq sum1 (+ sum1 element)))
    (dolist (element list)
	    (setq sum2 (+ sum2 (* 2 element))))
    (format *standard-output* "First sum: ~a~%Second sum: ~a~%" sum1 sum2)
))
  


(DEFMACRO GENRETURN (VALUE) 
  (LIST 
   (QUOTE THROW) 
   (QUOTE 
    (QUOTE GENERATOR-RETURN)) 
   VALUE))
 
(DEFUN GENERATOR (X) 
  (CATCH 
   (QUOTE GENERATOR-RETURN)
   (SETQ *TRACE-RULE-INDENT* 0)
   (SETF *GENKIT-STACK* NIL)
   (GG-START X))) 

(DEFUN GG-VP (X0)
  (UNLESS 
    (MEMBER 
     (CONS (QUOTE GG-VP) X0)
     *GENKIT-STACK*
     :TEST (FUNCTION EQUALP))
    (PUSH (CONS (QUOTE GG-VP) X0) *GENKIT-STACK*)
    (LET (X RESULT RESULT-STRING TEMP)
      (TRACE-GENKIT-NTERM (QUOTE GG-VP) (QUOTE <VP>) X0)
      (SETQ *TRACE-RULE-INDENT*
            (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*))
      (SETQ RESULT 
            (OR 
             (TRACE-RULE-CALL
              <VP>
              1
              (PROGN 
                (SETQ X (LIST (LIST (LIST (QUOTE X0) X0))))
                (AND 
                 (P=P (X1) (X0))
                 (OR-DOLIST (FS X)
                  (PROGN 
                    (SETQ RESULT-STRING "")
                    (AND 
                     (PROGN 
                       (SETQ TEMP (GG-V (GETVALUE FS (QUOTE (X1)))))
                       (IF TEMP
                           (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP))
                           (PROGN (SETQ RESULT-STRING "") NIL))))
                    (IF (ZEROP (LENGTH RESULT-STRING))
                        NIL
                        RESULT-STRING))))))
             (TRACE-RULE-CALL
              <VP>
              2
              (PROGN 
                (SETQ X (LIST (LIST (LIST (QUOTE X0) X0))))
                (AND 
                 (P==P (X2) (X0 OBJ))
                 (P=P (X1) (X0))
                 (OR-DOLIST
                  (FS X)
                  (PROGN 
                    (SETQ RESULT-STRING "")
                    (AND 
                     (PROGN 
                       (SETQ TEMP (GG-V (GETVALUE FS (QUOTE (X1))))) 
                       (IF TEMP 
                           (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP))
                           (PROGN (SETQ RESULT-STRING "") NIL)))
                     (PROGN 
                       (SETQ TEMP (GG-NP (GETVALUE FS (QUOTE (X2)))))
                       (IF TEMP 
                           (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING " " TEMP))
                           (PROGN (SETQ RESULT-STRING "") NIL))))
                    (IF (ZEROP (LENGTH RESULT-STRING))
                        NIL 
                        RESULT-STRING)))))))) 
      (SETQ *TRACE-RULE-INDENT* 
            (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*))
      (POP *GENKIT-STACK*)
      (TRACE-GENKIT-NTERM-RESULT 
       (QUOTE GG-VP) 
       (QUOTE <VP>)
       RESULT)
      RESULT))) 

(DEFUN GG-V (X0) (UNLESS (MEMBER (CONS (QUOTE GG-V) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-V) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-V) (QUOTE <V>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <V> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=L (X1 VALUE) (INFLECT (X0 CAT) (X0))) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" (MAKE-IT-STRING (GETVALUE FS (QUOTE (X1 VALUE))))))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-V) (QUOTE <V>) RESULT) RESULT))) 

(DEFUN GG-P (X0) (UNLESS (MEMBER (CONS (QUOTE GG-P) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-P) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-P) (QUOTE <P>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <P> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=L (X1 VALUE) (INFLECT (X0 CAT) (X0))) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" (MAKE-IT-STRING (GETVALUE FS (QUOTE (X1 VALUE))))))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-P) (QUOTE <P>) RESULT) RESULT))) 

(DEFUN GG-PP (X0) (UNLESS (MEMBER (CONS (QUOTE GG-PP) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-PP) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-PP) (QUOTE <PP>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <PP> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P==P (X2) (X0 OBJ)) (P=P (X1) (X0)) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (PROGN (SETQ TEMP (GG-P (GETVALUE FS (QUOTE (X1))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP)) (PROGN (SETQ RESULT-STRING "") NIL))) (PROGN (SETQ TEMP (GG-NP (GETVALUE FS (QUOTE (X2))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING " " TEMP)) (PROGN (SETQ RESULT-STRING "") NIL)))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-PP) (QUOTE <PP>) RESULT) RESULT))) 

(DEFUN GG-N (X0) (UNLESS (MEMBER (CONS (QUOTE GG-N) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-N) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-N) (QUOTE <N>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <N> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=L (X1 VALUE) (INFLECT (X0 CAT) (X0))) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" (MAKE-IT-STRING (GETVALUE FS (QUOTE (X1 VALUE))))))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-N) (QUOTE <N>) RESULT) RESULT))) 

(DEFUN GG-START (X0)
  (UNLESS
    (MEMBER
     (CONS (QUOTE GG-START) X0)
     *GENKIT-STACK*
     :TEST (FUNCTION EQUALP))
    (PUSH (CONS (QUOTE GG-START) X0) *GENKIT-STACK*)
    (LET (X RESULT RESULT-STRING TEMP)
      (TRACE-GENKIT-NTERM (QUOTE GG-START) (QUOTE <START>) X0)
      (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*))
      (SETQ RESULT
            (OR 
             (TRACE-RULE-CALL 
              <START> 
              1
              (PROGN 
                (SETQ X (LIST (LIST (LIST (QUOTE X0) X0))))
                (AND 
                 (P=P (X1) (X0))
                 (OR-DOLIST 
                  (FS X) 
                  (PROGN 
                    (SETQ RESULT-STRING "") 
                    (AND 
                     (PROGN 
                       (SETQ TEMP (GG-NP (GETVALUE FS (QUOTE (X1)))))
                       (IF TEMP 
                           (SETQ RESULT-STRING 
                                 (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP))
                           (PROGN (SETQ RESULT-STRING "") NIL))))
                    (IF (ZEROP (LENGTH RESULT-STRING)) 
                        NIL 
                        RESULT-STRING))))))
             (TRACE-RULE-CALL 
              <START> 
              2 
              (PROGN 
                (SETQ X (LIST (LIST (LIST (QUOTE X0) X0))))
                (AND 
                 (P=CA (X0 CAT) V) 
                 (P=P (X1) (X0 SUBJ)) 
                 (P=P (X2) (X0)) 
                 (OR-DOLIST 
                  (FS X) 
                  (PROGN 
                    (SETQ RESULT-STRING "")
                    (AND 
                     (PROGN 
                       (SETQ TEMP (GG-NP (GETVALUE FS (QUOTE (X1)))))
                       (IF TEMP 
                           (SETQ RESULT-STRING 
                                 (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP))
                           (PROGN (SETQ RESULT-STRING "") NIL)))
                     (PROGN 
                       (SETQ TEMP (GG-VP (GETVALUE FS (QUOTE (X2))))) 
                       (IF TEMP 
                           (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING " " TEMP)) 
                           (PROGN 
                             (SETQ RESULT-STRING "") NIL))))
                    (IF (ZEROP (LENGTH RESULT-STRING))
                        NIL
                        RESULT-STRING))))))))
      (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*))
      (POP *GENKIT-STACK*)
      (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-START) (QUOTE <START>) RESULT) RESULT))) 

(DEFUN GG-DET (X0) (UNLESS (MEMBER (CONS (QUOTE GG-DET) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-DET) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-DET) (QUOTE <DET>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <DET> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=L (X1 VALUE) (INFLECT (X0 CAT) (X0))) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" (MAKE-IT-STRING (GETVALUE FS (QUOTE (X1 VALUE))))))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-DET) (QUOTE <DET>) RESULT) RESULT))) 

(DEFUN GG-NP (X0) (UNLESS (MEMBER (CONS (QUOTE GG-NP) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-NP) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-NP) (QUOTE <NP>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <NP> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P==P (X1) (X0 DET)) (P=P (X2) (X0)) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (PROGN (SETQ TEMP (GG-DET (GETVALUE FS (QUOTE (X1))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP)) (PROGN (SETQ RESULT-STRING "") NIL))) (PROGN (SETQ TEMP (GG-N (GETVALUE FS (QUOTE (X2))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING " " TEMP)) (PROGN (SETQ RESULT-STRING "") NIL)))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))) (TRACE-RULE-CALL <NP> 2 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=A (X0 CAT) N) (P=P (X1) (X0)) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (PROGN (SETQ TEMP (GG-N (GETVALUE FS (QUOTE (X1))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP)) (PROGN (SETQ RESULT-STRING "") NIL)))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))) (TRACE-RULE-CALL <NP> 3 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=A (X0 CAT) PRO) (P=P (X1) (X0)) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (PROGN (SETQ TEMP (GG-PRO (GETVALUE FS (QUOTE (X1))))) (IF TEMP (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" TEMP)) (PROGN (SETQ RESULT-STRING "") NIL)))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-NP) (QUOTE <NP>) RESULT) RESULT))) 

(DEFUN GG-PRO (X0) (UNLESS (MEMBER (CONS (QUOTE GG-PRO) X0) *GENKIT-STACK* :TEST (FUNCTION EQUALP)) (PUSH (CONS (QUOTE GG-PRO) X0) *GENKIT-STACK*) (LET (X RESULT RESULT-STRING TEMP) (TRACE-GENKIT-NTERM (QUOTE GG-PRO) (QUOTE <PRO>) X0) (SETQ *TRACE-RULE-INDENT* (+ *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (SETQ RESULT (OR (TRACE-RULE-CALL <PRO> 1 (PROGN (SETQ X (LIST (LIST (LIST (QUOTE X0) X0)))) (AND (P=L (X1 VALUE) (INFLECT (X0 CAT) (X0))) (OR-DOLIST (FS X) (PROGN (SETQ RESULT-STRING "") (AND (SETQ RESULT-STRING (CONCATENATE (QUOTE STRING) RESULT-STRING "" (MAKE-IT-STRING (GETVALUE FS (QUOTE (X1 VALUE))))))) (IF (ZEROP (LENGTH RESULT-STRING)) NIL RESULT-STRING)))))))) (SETQ *TRACE-RULE-INDENT* (- *TRACE-RULE-INDENT* *TRACE-RULE-INDENT-FACTOR*)) (POP *GENKIT-STACK*) (TRACE-GENKIT-NTERM-RESULT (QUOTE GG-PRO) (QUOTE <PRO>) RESULT) RESULT))) 